import 'dart:collection';

import 'package:changxindianzishangwu/cache/local_cache.dart';
import 'package:changxindianzishangwu/http/base/ec_base_request.dart';
import 'package:changxindianzishangwu/http/request/common_language_add_cyy_request.dart';
import 'package:changxindianzishangwu/http/request/common_language_add_request.dart';
import 'package:changxindianzishangwu/http/request/common_language_cyy_request.dart';
import 'package:changxindianzishangwu/http/request/common_language_delete_cyy_request.dart';
import 'package:changxindianzishangwu/http/request/common_language_delete_request.dart';
import 'package:changxindianzishangwu/http/request/common_language_request.dart';
import 'package:changxindianzishangwu/http/request/common_language_update_cyy_request.dart';
import 'package:changxindianzishangwu/http/request/common_language_update_request.dart';
import 'package:changxindianzishangwu/http/zd_net.dart';

class CommonLanguageDao {
  ///1打招呼 2离线自动回复 3常用语【另外的接口】
  static getData(int type) async {
    EcBaseRequest request = type == 3
        ? new CommonLanguageCyyRequest()
        : new CommonLanguageRequest();
    type == 3
        ? request.add("userId", getUserInfo().userId)
        : request.add("type", type);
    request.add("access_token", getAppLoginToken());

    return await ZdNet.getInstance().send(request);
  }

  static saveData(int type, String context) async {
    EcBaseRequest request = type == 3
        ? new CommonLanguageAddCyyRequest()
        : new CommonLanguageAddRequest();
    request
        .add("type", type)
        .add("userId", getUserInfo().userId)
        .add("context", context)
        .add("access_token", getAppLoginToken());

    // LinkedHashMap result= await ZdNet.getInstance().send(request);
    return await ZdNet.getInstance().send(request);
  }

  static deleteData(int type, String id) async {
    EcBaseRequest request = type == 3
        ? new CommonLanguageDeleteCyyRequest()
        : new CommonLanguageDeleteRequest();
    if (type == 3) {
      request
          .add("userId", getUserInfo().userId)
          .add("commonId", id)
          .add("access_token", getAppLoginToken());
    } else {
      request
          .add("type", type)
          .add("sayHelloId", id)
          .add("access_token", getAppLoginToken());
    }

    // LinkedHashMap result= await ZdNet.getInstance().send(request);
    return await ZdNet.getInstance().send(request);
  }

  static updateData(int type, String id, String context) async {
    EcBaseRequest request = type == 3
        ? new CommonLanguageUpdateCyyRequest()
        : new CommonLanguageUpdateRequest();
    if (type == 3) {
      request
          .add("commonId", id)
          .add("userId", getUserInfo().userId)
          .add("context", context)
          .add("access_token", getAppLoginToken());
    } else {
      request
          .add("type", type)
          .add("sayHelloId", id)
          .add("context", context)
          .add("access_token", getAppLoginToken());
    }

    // LinkedHashMap result= await ZdNet.getInstance().send(request);
    return await ZdNet.getInstance().send(request);
  }
}
